package com.mgq.design.observer;

/**
 * <b>功能：</b>Client<br>
 * <b>Copyright TCSL</b>
 * <li>版本&nbsp;&nbsp;&nbsp;&nbsp;修改日期&nbsp;&nbsp;&nbsp;&nbsp;部　　门&nbsp;&nbsp;&nbsp;&nbsp;作　者&nbsp;&nbsp;&nbsp;&nbsp;变更内容</li><hr>
 * <li>v1.0&nbsp;&nbsp;&nbsp;&nbsp;20220418&nbsp;&nbsp;营业后台&nbsp;&nbsp;&nbsp;&nbsp;马广奇&nbsp;&nbsp;&nbsp;&nbsp;创建类</li>
 * <br><br>
 *
 * @author 马广奇
 * @version 2022-04-18 11:57
 */
public class Client {
    public static void main(String[] args) {
        Feed feed = new Feed();
        feed.registerObservers(new NYTimes());
        feed.registerObservers(new Guardian());
        feed.registerObservers(new LeMonde());
        feed.notifyObservers("The queen said her favourite book is Java 8 in Action!\"");


        //使用lambda表达式来简化
        feed.registerObservers(tweet -> {
            //只关注money相关的消息
            if (tweet != null && tweet.contains("money")) {
                System.out.println("Breaking news in NY! " + tweet);
            }
        });

        feed.registerObservers(tweet -> {
            //只关注包含Queen(女王)的news
            if (tweet != null && tweet.contains("queen")) {
                System.out.println("Yet another news in London... " + tweet);
            }
        });
        feed.registerObservers(tweet -> {
            //只关注酒类
            if (tweet != null && tweet.contains("wine")) {
                System.out.println("Today cheese, wine and news! " + tweet);
            }
        });
    }
}
